package cn.bdqn.appinfo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import cn.bdqn.appinfo.entity.AppCategory;
import cn.bdqn.appinfo.entity.AppInfo;
import cn.bdqn.appinfo.service.AppInfoService;
import cn.bdqn.appinfo.util.Page;
import cn.bdqn.appinfo.util.Result;

@RequestMapping("/appinfos")
@Controller
public class AppinfoController {
	@Autowired private AppInfoService appInfoService;
	
	@RequestMapping(value={""},method=RequestMethod.POST)
	@ResponseBody
	public Result add(AppInfo appInfo, MultipartFile myfile) {
		System.out.println(appInfo.getApkName());
		if(myfile!=null) {
			System.out.println(myfile.getOriginalFilename());
		}
		return Result.ok();
	}
	
	@RequestMapping("/category")
	@ResponseBody
	public Result findCategory(Integer parentId) throws Exception {
		List<AppCategory> list = appInfoService.findAppCategoryByParentId(parentId);
		return Result.ok(list);
	}
	
	@RequestMapping("")
	@ResponseBody
	public Result findAll(AppInfo appInfo, @RequestParam("page")Integer pageNo, @RequestParam("limit")Integer pageSize) {
		Page<AppInfo> page = new Page<AppInfo>();
		page.setPageNo(pageNo==null?1:pageNo);
		page.setPageSize(pageSize==null?5:pageSize);
		appInfoService.find(appInfo, page);
		return Result.ok(page);
	}
}
